import datetime
import random
import time
from time import sleep

import requests
import json
import win32api
import os

def register(username,password,email):
    data = {
        "showtype":"ajax",
        "sxid":"0",
        "regtype":"0",
        "username":username,
        "email":email,
        "pwd":password,
    }
    print(data)
    strtime = time.time()
    strtime = (strtime*1000).__str__()
    str2 = "."
    str = strtime[:strtime.index(str2)]
    print(str)
    print(data.__str__().__len__())
    heads = {
        "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
        "Referer":"http://www.lbjs99.com/index.php?p=usercenter&t=register",
        "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36",
        "X-Requested-With":"XMLHttpRequest",
        "Cookie":"UM_distinctid=16dfe94acbf5c-0ff212f13a500c-b363e65-1fa400-16dfe94acc0942; CNZZDATA1276875005=401893505-1571929557-null%7C1571929557",
        "Content-Length":data.__str__().__len__().__str__(),
        "Accept":"application/json, text/javascript, */*; q=0.01",
    }
    proxies = {
        # "http": "http://117.28.244.154:8070",
        # "http": "http://127.0.0.1:65110",
        "http": "127.0.0.1:1081",
        # "https": "https://221.228.17.172:8181",
    }
    r1 = requests.post("http://www.jilinlx.com//index.php?p=usercenter&t=register&s"+str, data=data,headers=heads)
    return r1
# 1571936336613.8254
# 1571935945457
# 1571935093135
# 00:50:17.104514
def run():
    while(1):
        time_now = datetime.datetime.now().strftime('%H:%M:%S.%f')
        j = 8
        id = []
        username = "a"+(''.join(str(i) for i in random.sample(range(0, 9), j)))
        print(username)
        pwd = "123123"
        email = username+"@qq.com"
        res = register(username,pwd,email)
        print("test:"+res.text)
        data = json.loads(res.text)
        if(data['code'] == 1):
            updateStr = """
            [Soft-LeiBaoJsq]
            yqm=
            login_username="""+username+"""
            login_remepwd=1
            login_userpwd=4E89FBCD1A30D126EABFBDF093F4FCF1
            login_autologin=1
            """
            f = open('F:\\other\\vpn\\data\\config.ini', 'w+', encoding='UTF-8')
            f.write(updateStr)
            f.close()
            os.system("taskkill /F /IM LieBao.exe")
            win32api.ShellExecute(0, 'open', r'F:\\other\\vpn\\LieBao.exe', '','',1)
            sleep(60*60)
        # 判断是否注册成功,如果注册成功那么就修改本地猎豹配置文件 猎豹加速器\data\config.ini
        # [Soft-LeiBaoJsq]
        # yqm=
        # login_username=账号
        # login_remepwd=1
        # login_userpwd=4E89FBCD1A30D126EABFBDF093F4FCF1
        # login_autologin=1
        sleep(1)


if __name__ == '__main__':
    run()